<template>
    <el-dialog :title="info.title" :visible="dialogFormVisible" width="35%" :before-close="cancel">
        <strong style="display: inline-block;height: 20px;">请输入类目名称:</strong>
        <el-input v-model="input" autocomplete="off"></el-input>
        <div slot="footer" class="dialog-footer">
            <el-button @click="cancel">取 消</el-button>
            <el-button type="primary" @click="submit">确 定</el-button>
        </div>
    </el-dialog>
</template>
<script>
import { changeNodes, editorNodes, addOneNodes } from '@/api/request/product/index'
export default {
    name: 'dialog-page',
    props: ['type', 'info'],
    data() {
        return {
            input: '',
            dialogFormVisible: false
        }
    },
    methods: {
        cancel() {
            this.dialogFormVisible = false
            this.input = ''
        },
        async submit() {
            let param = { cid: this.info.cid, name: this.input }
            let res = {}
            if (this.info.cid == '') {   // 增加一级导航类目 大按钮
                res = await addOneNodes('add-one-nodes', { name: this.input })
            } else {
                res = this.type == 1 ? await changeNodes('/chang-nodes', param) : await editorNodes('/node-edit', param)
            }
            if (res.code != 200) return this.$message.error('error')
            this.$message.success(res.message)
            // this.$emit('refresh')    // 方法1
            this.$parent.cotryNodes()    // 方法2 子组件直接调用父组件 属性 方法
            this.input = ''
            this.dialogFormVisible = false
        },
    }
}
</script>
<style scoped lang="less"></style>